<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>网关基本信息管理</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
		
			//设置当前层级
			if('${nowLevel}' != ""){
				$("#nowLevel").html("[" + "${nowLevel}" + "]");
			}
		
			$("#all").click(function() {
				if (this.checked) {
					$("#check :checkbox").prop("checked", true);
				} else {
					$("#check :checkbox").prop("checked", false);}
			});
			
			$(".checktr").click(function(e){  
			    var check = $(this).find("input[type='checkbox']");  
			    if(check){  
			        var flag = check[0].checked;  
			        if(flag){  
			            check[0].checked = false;  
			        }else{  
			            check[0].checked = true;  
			        }  
			    }  
			});
		
		});
		
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
		
		 function Delete(){
			if(confirm("确定要删除监测设备吗？")){
	       		$("#check").find(":checkbox").each(function(){
				
	              	if($(this).is(":checked")){
					//获取后面td 的内容即 id
						var tr = $(this).closest("tr");
						var gwMac = tr.find("td:eq(1)").text();
						var ID = tr.find("td:eq(8)").text(); 
					 	$.ajax({
							type: "post",
							dataType: "json",
							url: "${ctx}/ccgwinfo/gatewayInfo/deleteGateWayInfo",
							data: {"gwMac":gwMac,"id":ID},
							timeout: 60000,
							success: function(data){
								//成功关闭页面，存在不关闭页面	
								location.reload(); //刷新当前页面
								alert("删除监测设备信息成功！");	
							},
						}); 
						
					 }  	
	            });
           		
	        }
			
        }
		
		
         function Add(){
			openWindowsH400("${ctx}/ccgwinfo/gatewayInfo/addGateway","",800,550);
		}
		 
		function Edit(){
			//修改按钮的监听事件在此处，待写
			//var t=$("table tr:eq(1) td:eq(1)").text();
			// alert(t); 
			var count = $("#check").find(":checked").length;

			if(count > 1 ||count < 1){
				/* $.jBox.alert("无法确定对应设备信息，请选择一条设备信息！");
				return false; */
				if(confirm('无法确定对应设备信息，请选择一条设备信息！'))
					return false; 

				return false;  
			}
			
			$("#check").find(":checkbox").each(function(){
				
              	if($(this).is(":checked")){
				//获取后面td 的内容即 id
					var tr = $(this).closest("tr");
					var gwMac = tr.find("td:eq(1)").text();
				 	openWindowsH400("${ctx}/ccgwinfo/gatewayInfo/editGateway?gwMac="+gwMac,"修改监测设备",800,550); }  	

            });

		}
		
		function openWindowsH400(url, title, w, h) {
			w = isNull(w) ? 800 : w;
			h = isNull(h) ? 550 : h;
			var ww = ($(document).width() < w ? $(document).width() - 30 : w)
					+ "px";
			var hh = ($(document).height() < h ? $(document).height() - 30 : h)
					+ "px";
			layer.open({
				type : 2,
				area : [ ww, hh ],
				title : isNull(title) ? "添加监测仪器" : title,
				fix : false, //不固定
				maxmin : false,
				shade : 0.3,
				shift : 0, //0-6的动画形式，-1不开启
				content : url,
			});
		}
		
		function closeTree(){
			var openCloseDiv = document.getElementById('openClose'); 
			openCloseDiv.click();
		}
	</script>
	<style type="text/css">
		body{
			color: #000000;
		}
		#officeContent{
			border: none;
		}
		#nowLevel{
			color: #000;
		}
	</style>
</head>
<body>
	<div id="content" class="row-fluid">
		<div id="left">
		<div class="accordion-heading">
			<a class="accordion-toggle">组织树
				<i id="colseBtn" class="icon-remove pull-right" onclick="closeTree();"></i>
				<label id="nowLevel"></label>
			</a>
		</div>
			<iframe id="officeContent" src="${ctx}/cchierarchy/hierarchy/list" width="100%" height="95%" ></iframe>
		</div>
		<div id="openClose" class="close">&nbsp;</div>
		<div id="right">
			<ul class="nav nav-tabs">
				<li class="active"><a href="${ctx}/ccgwinfo/gatewayInfo/">监测仪器</a></li>
				<shiro:hasPermission name="ccgwinfo:gatewayInfo:edit"><li><a href="${ctx}/ccgwinfo/gatewayInfo/form">网关基本信息添加</a></li></shiro:hasPermission>
			</ul>
			<form:form id="searchForm" modelAttribute="gatewayInfo" action="${ctx}/ccgwinfo/gatewayInfo/" method="post" class="breadcrumb form-search">
				<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
				<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
				<ul class="ul-form">
					<li style="margin-top: 2px;">监测设备名称</li>
					<li style="margin-left: 15px;">
						<form:input path="name" htmlEscape="false" maxlength="255" class="input-medium"/>
					</li>
					<li class="btns" style="margin-left: 15px;"><input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/></li>
					<li class="btns" style="margin-left: 5px;"><input onclick="Add()"  class="btn btn-primary" type="button" value="新增"/></li>
					<li class="btns" style="margin-left: 5px;"><input onclick="Edit()"  class="btn btn-primary" type="button" value="修改"/></li>
					<li class="btns" style="margin-left: 5px;"><input onclick="Delete()" class="btn btn-primary" type="button" value="删除"/></li>
					<li class="clear fix"></li>
				</ul>
			</form:form>
			<sys:message content="${message}"/>
			<table id="contentTable" class="table table-striped table-bordered table-condensed">
				<thead>
					<tr  style="width:200px; height:35px;">		
						<th><input id="all" type="checkbox"></th>
						<th>网关编号</th>
						<th>名称</th>
						<th>用途</th>
						<th>服务器IP</th>
						<th>启用日期</th>
						<th>保修期(月)</th>
						<th>状态</th>
						<th style="display: none">ID</th>
					</tr>
				</thead>
				<tbody id="check">
				<c:forEach items="${page.list}" var="gatewayInfo">
					<!-- <tr>
					
						<td style="width: 10px;"><span><input type="checkbox"></span></td>
					 -->
					 <tr data-id="gwMac" class = "checktr"  style="width:200px; height:35px;">
						<td style="width: 10px; "><span><input type="checkbox" id="${gatewayInfo.id}"></span></td>
								
						<td>
							${gatewayInfo.gwMac}
						</td>
						<td>
							${gatewayInfo.name}
						</td>
						<td>
							${gatewayInfo.purpose}
						</td>
						<td>
							${gatewayInfo.severIp}
						</td>
						<td>
							<fmt:formatDate value="${gatewayInfo.startuseDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
						</td>
						<td>
							${gatewayInfo.warrantyPeriod}
						</td>
						<td>
							${gatewayInfo.status}
						</td>
						<td  style="display: none;">
							${gatewayInfo.id}
						</td>
						<!--  
						<shiro:hasPermission name="ccgwinfo:gatewayInfo:edit"><td>
		    				<a href="${ctx}/ccgwinfo/gatewayInfo/form?id=${gatewayInfo.id}">修改</a>
							<a href="${ctx}/ccgwinfo/gatewayInfo/delete?id=${gatewayInfo.id}" onclick="return confirmx('确认要删除该网关基本信息吗？', this.href)">删除</a>
						</td></shiro:hasPermission>
						-->
					</tr>
				</c:forEach>
				</tbody>
			</table>
			<div class="pagination">${page}</div>
		</div>
	</div>
	<script type="text/javascript">
	   		
		var leftWidth = "350"; // 左侧窗口大小
		var htmlObj = $("html"), mainObj = $("#main");
		var frameObj = $("#left, #openClose, #right, #right iframe");
		function wSize(){
			var strs = getWindowSize().toString().split(",");
			/* htmlObj.css({"overflow-x":"hidden", "overflow-y":"hidden"}); */
			mainObj.css("width","auto");
			frameObj.height(strs[0] - 5);
			var leftWidth = ($("#left").width() < 0 ? 0 : $("#left").width());
			$("#right").width($("#content").width()- leftWidth - $("#openClose").width() -5);
			$(".ztree").width(leftWidth - 10).height(frameObj.height() - 46);
		}
	</script>
	<script src="${ctxStatic}/common/wsize.min.js" type="text/javascript"></script>
	
</body>
</html>